#include "linestrimbar.h"
#include "ui_linestrimbar.h"

LinesTrimBar::LinesTrimBar(QWidget *parent) :
    SideBarBase(parent),
    ui(new Ui::LinesTrimBar)
{
    ui->setupUi(this);
    setObjectName("LinesTrimBar");
    setupBar(tr("Trim Empty Lines"), true);

    QMenu *trimEOLsMenu = new QMenu(this);
    ui->pbTrimEOLs->setMenu(trimEOLsMenu);
    connect(trimEOLsMenu, SIGNAL(triggered(QAction*)), this, SLOT(trimEolMenu_activated(QAction*)));

    QAction* winEolAct = new QAction(QIcon(":/images/win22.png"), tr("Windows"), this);
    winEolAct->setStatusTip(tr("Trim Windows-style line ends (CR/LF)"));
    winEolAct->setData(QsciScintilla::EolWindows);
    trimEOLsMenu->addAction(winEolAct);

    QAction* unixEolAct = new QAction(QIcon(":/images/linux22.png"), tr("Unix"), this);
    unixEolAct->setStatusTip(tr("Trim Unix-style line ends (LF)"));
    unixEolAct->setData(QsciScintilla::EolUnix);
    trimEOLsMenu->addAction(unixEolAct);

    QAction* macEolAct = new QAction(QIcon(":/images/mac22.png"), tr("Mac"), this);
    macEolAct->setStatusTip(tr("Trim Mac-style line ends (CR)"));
    macEolAct->setData(QsciScintilla::EolMac);
    trimEOLsMenu->addAction(macEolAct);
}

LinesTrimBar::~LinesTrimBar()
{
    delete ui;
}

void LinesTrimBar::changeEvent(QEvent *e)
{
    QWidget::changeEvent(e);
    switch (e->type())
    {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void LinesTrimBar::on_pbTrimAll_clicked()
{
  TrimInfo ti;
  ti.count = 0;
  ti.isAbove = true;
  emit trim(ti);
}

void LinesTrimBar::on_pbTrimAbove_clicked()
{
  TrimInfo ti;
  ti.count = ui->sbLines->value();
  ti.isAbove = true;
  emit trim(ti);
}

void LinesTrimBar::on_pbTrimBelow_clicked()
{
  TrimInfo ti;
  ti.count = ui->sbLines->value();
  ti.isAbove = false;
  emit trim(ti);
}


void LinesTrimBar::trimEolMenu_activated(QAction *act)
{
  emit trimEOLs((QsciScintilla::EolMode)act->data().toInt());
}
